﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Configuration;
using Helper;

namespace MVC2_Test.Models
{
    [Table(Name = "Member")]
    public class Member
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        internal int MemberID { get; set; }

        [Column]
        public string LoginName { get; set; }

        [Column]
        public int ReputationPoints { get; set; }


        public void AddMember(string loginName, int addReputationPoints)
        {
            DataContext dc = new DataContext(ConnectionStringHelper.GetConnectionString("TestDBConn"));
            
            dc.GetTable<Member>().InsertOnSubmit(new Member
            {
                LoginName = loginName,
                ReputationPoints = 10 + addReputationPoints
            });

            dc.SubmitChanges();
        }

        public void AddMember(string loginName)
        {
            AddMember(loginName, 0);
        }
    }


}